package com.mariusz.ui.models;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.mariusz.data.dto.Rentier;
import com.mariusz.data.dto.Room;

public class LocatorsTableModel extends AbstractTableModel {
	private static final String[] LOCATORS_TABLE_HEADER = new String[] {
		"Name", "Room"}; 
	private List<Rentier> rentiers;

	public LocatorsTableModel(List<Rentier> rentiers) {
		this.rentiers = rentiers;
	}

	@Override
	public int getColumnCount() {
		return LOCATORS_TABLE_HEADER.length;
	}

	public String getColumnName(int i) {
		return LOCATORS_TABLE_HEADER[i];
	}

	@Override
	public int getRowCount() {
		if (rentiers != null) {
			return rentiers.size();
		} else {
			return 0;
		}
	}

	public Class getColumnClass(int c) {
		if (rentiers.size() > 0) {
			return getValueAt(0, c).getClass();
		} else {
			// return default
			return String.class;
		}
	}

	public boolean isCellEditable(int row, int col) {
		return false;
	}

	public void setValueAt(Object value, int row, int col) {
		return;
	}

	@Override
	public Object getValueAt(int row, int col) {
		switch (col) {
		
		case 0:
			return rentiers.get(row).getName();
		case 1:
			if (rentiers.size() > 0) {
				Room r = rentiers.get(row).getRoom();
				if (r != null) {
					return r.getName();
				}
			}
			return "";
		}
		return null;
	}
	
	public Rentier getAt(int i){
		return rentiers.get(i);
	}
}